package com.example.zzbus.base;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.FragmentActivity;
import android.view.MenuItem;

import com.example.zzbus.R;
import com.example.zzbus.data.UserData;
import com.example.zzbus.ui.LoginActivity;
import com.example.zzbus.ui.MeActivity;

import baidumapsdk.demo.search.BusLineSearchDemo;
import baidumapsdk.demo.search.RoutePlanDemo;

public class MapBase extends FragmentActivity {
    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            if (isstart){
                return true;
            }
            switch (item.getItemId()) {
                case R.id.navigation_home:
                   startActivity(new Intent(MapBase.this, RoutePlanDemo.class));
                   finish();
                   overridePendingTransition(0, 0);
                    return true;
                case R.id.navigation_dashboard:
                    startActivity(new Intent(MapBase.this, BusLineSearchDemo.class));
                    finish();
                    overridePendingTransition(0, 0);
                    return true;
                case R.id.navigation_notifications:
                    if (UserData.isLogin()){
                        startActivity(new Intent(MapBase.this, MeActivity.class));
                    }else{
                        startActivity(new Intent(MapBase.this, LoginActivity.class));
                    }
                    finish();
                    overridePendingTransition(0, 0);
                    return true;
            }
            return false;
        }
    };
    boolean isstart=false;
    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        isstart=true;
    }

    @Override
    protected void onResume() {
        super.onResume();
        isstart=false;
    }

    public void iniBar(int postion){
        BottomNavigationView navView = findViewById(R.id.nav_view);
        navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
        navView.setSelectedItemId(navView.getMenu().getItem(postion).getItemId());
    }

    @Override
    protected void onPause() {
        super.onPause();
        overridePendingTransition(0, 0);
    }
}
